﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using StoragePeriod.IDAL.FoodTesting;
using StoragePeriod.DALFactory;
using StoragePeriod.Model.FoodTesting;
using System.Data;

namespace StoragePeriod.BLL.FoodTesting
{
    /// <summary>
	/// VE含量检测
	/// </summary>
	public partial class T_VAData
	{
        I_VAData dal = new DataAccess<I_VAData>().CreateInstance("FoodTesting.D_VAData");
		public T_VAData()
		{}
		#region  Method
		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(int id)
		{
			return dal.Exists(id);
		}

		/// <summary>
		/// 增加一条数据
		/// </summary>
		public int  Add(E_VAData model)
		{
			return dal.Add(model);
		}

		/// <summary>
		/// 更新一条数据
		/// </summary>
        public bool Update(E_VAData model)
		{
			return dal.Update(model);
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(int id)
		{
			
			return dal.Delete(id);
		}
		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool DeleteList(string idlist )
		{
			return dal.DeleteList(idlist );
		}

		/// <summary>
		/// 得到一个对象实体
		/// </summary>
        public E_VAData GetModel(int id)
		{
			
			return dal.GetModel(id);
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			return dal.GetList(strWhere);
		}
		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			return dal.GetList(Top,strWhere,filedOrder);
		}
		/// <summary>
		/// 获得数据列表
		/// </summary>
        public List<E_VAData> GetModelList(string strWhere)
		{
			DataSet ds = dal.GetList(strWhere);
			return DataTableToList(ds.Tables[0]);
		}
		/// <summary>
		/// 获得数据列表
		/// </summary>
        public List<E_VAData> DataTableToList(DataTable dt)
		{
            List<E_VAData> modelList = new List<E_VAData>();
			int rowsCount = dt.Rows.Count;
			if (rowsCount > 0)
			{
                E_VAData model;
				for (int n = 0; n < rowsCount; n++)
				{
                    model = new E_VAData();
					if(dt.Rows[n]["id"].ToString()!="")
					{
						model.id=int.Parse(dt.Rows[n]["id"].ToString());
					}
					if(dt.Rows[n]["RawID"].ToString()!="")
					{
						model.RawID=int.Parse(dt.Rows[n]["RawID"].ToString());
					}
					model.RawName=dt.Rows[n]["RawName"].ToString();
					model.Result=dt.Rows[n]["Result"].ToString();
					if(dt.Rows[n]["FoodTime"].ToString()!="")
					{
						model.FoodTime=DateTime.Parse(dt.Rows[n]["FoodTime"].ToString());
					}
					if(dt.Rows[n]["FoodNum"].ToString()!="")
					{
						model.FoodNum=int.Parse(dt.Rows[n]["FoodNum"].ToString());
					}
					modelList.Add(model);
				}
			}
			return modelList;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetAllList()
		{
			return GetList("");
		}

		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		//public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		//{
			//return dal.GetList(PageSize,PageIndex,strWhere);
		//}

        /// <summary>
        /// 根据原料ID和检测时间 删除检测记录
        /// </summary>
        /// <param name="eVcData">要删除的检测记录</param>
        /// <returns></returns>
        public int RemoveByTime(E_VAData eVAData)
        {
            return dal.RemoveByTime(eVAData);
        }

        /// <summary>
        /// 删除某一次检测记录
        /// </summary>
        /// <param name="eVcData">要删除的检测记录</param>
        /// <returns></returns>
        public int RemoveByFoodNum(E_VAData eVAData)
        {
            return dal.RemoveByFoodNum(eVAData);
        }
		#endregion  Method
	}
}
